using System;
using System.Collections.Generic;
using System.Linq;
using DivideAndConquer.States;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using UCS.XNA.Utils;
using DivideAndConquer.States.InGame;

namespace DivideAndConquer
{
    public class DivideAndConquerGame : Game
    {
        #region Private Members

        private GraphicsDeviceManager _graphics;
        private SpriteBatch _spriteBatch;
        private GameState _currentState;

        #endregion

        #region Constructors

        public DivideAndConquerGame()
        {
            _graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            IsMouseVisible = true;
        }

        #endregion

        #region Overriden Methods

        protected override void Initialize()
        {
            base.Initialize();

            this.InitializeGameResources();
            this.InitializeCurrentGameState();
        }

        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
        }

        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            _currentState.Update(gameTime);

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            _currentState.Draw(gameTime);

            base.Draw(gameTime);
        }

        #endregion

        #region Private Methods

        private void InitializeGameResources()
        {
            GameResources.Graphics = this._graphics;
            GameResources.SpriteBatch = this._spriteBatch;
            GameResources.Content = this.Content;
        }

        private void InitializeCurrentGameState()
        {
            this._currentState = new InGameState();
        }

        #endregion
    }
}